package org.lql.algo.codecrush.week007;

/**
 * @author: liangqinglong
 * @date: 2025-08-18 13:41
 * @description: 162. 寻找峰值 <a href="https://leetcode.cn/problems/find-peak-element/description/">...</a>
 **/
public class FindPeakElement {

	public int findPeakElement(int[] nums) {
		int left = 0;
		int right = nums.length - 1;
		while (left < right) {
			int lmid = (left + right) / 2;
			int rmid = lmid + 1;
			if (nums[lmid] <= nums[rmid]) {
				left = lmid + 1;
			} else {
				right = rmid - 1;
			}
		}
		return right;
	}

	public static void main(String[] args) {
		int[] nums = new int[]{1, 2, 3, 1};
		System.out.println(new FindPeakElement().findPeakElement(nums));
		nums = new int[]{1, 2, 1, 3, 5, 6, 4};
		System.out.println(new FindPeakElement().findPeakElement(nums));
		nums = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		System.out.println(new FindPeakElement().findPeakElement(nums));
	}
}
